package com.example.AIstudy.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.example.AIstudy.domain.Exercise;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ExerciseDao extends BaseMapper<Exercise> {

    //分页获取练习题
    @Select("SELECT * FROM exercise ${ew.customSqlSegment}")
    public IPage<Exercise> findExercise(IPage<Exercise> page,
                                        @Param(Constants.WRAPPER) QueryWrapper<Exercise> wrapper);

    //新增一个学生的学习周记录
    @Insert("INSERT INTO exercise(category,problem,answer,sonProID,isSingle,score,choiceNum,knowledgeIDs,level," +
            "choice1,choice2,choice3,choice4,content,embedding) " +
            "VALUES (#{category},#{problem},#{answer},#{sonProID},#{isSingle},#{score},#{choiceNum},#{knowledgeIDs},#{level}," +
            "#{choice1},#{choice2},#{choice3},#{choice4},#{content},#{embedding})")
    @SelectKey(statement = "select last_insert_id()", keyProperty = "id",
            keyColumn = "id", resultType = Integer.class, before = false)
    void insertExercise(Exercise exercise);


    //获取子练习题（属于同一道大题）
    @Select("SELECT * FROM exercise ${ew.customSqlSegment}")
    public List<Exercise> findSonExercise(@Param(Constants.WRAPPER) QueryWrapper<Exercise> wrapper);

    @Select("SELECT * FROM exercise ${ew.customSqlSegment}")
    public List<Exercise> findExerciseByList(@Param(Constants.WRAPPER) QueryWrapper<Exercise> wrapper);
    //删除满足条件的题目
    @Select("delete FROM exercise ${ew.customSqlSegment}")
    public void deleteExercise(@Param(Constants.WRAPPER) QueryWrapper<Exercise> wrapper);

    @Select("select sonProID FROM exercise where id=#{exerciseID}")
    public String selectSonProID(Integer exerciseID);

    @Select("select * FROM exercise where esID=#{esID}")
    public Exercise selectByesID(String esID);

}
